import { createStore } from 'vuex'

export default createStore({
    state: {
        tabs: [],
        menus: [
            // 配置一级菜单和二级菜单          
            {
                menusIndex: "1",
                title: '会议室预定',
                icon: 'User',
                children: [
                    {
                        title: '管理我的预约',
                        path: '/personal/Unsubscribe'
                    },
                ]
            }
        ]
    },
    getters: {

        /**
         * 获取所有的tab
         * @param state
         * @returns
         */
        tabs(state) {
            return state.tabs;
        },

        /**
         * 获取所有的菜单
         * @param state
         * @returns
         */
        menus(state) {
            return state.menus;
        }

    },
    mutations: {
        addMenus(state, param) {
            state.menus = param
        },
        deleteTabByIndex(state, index) {
            state.tabs.splice(index, 1);
        },
        /**
         * 清空tab
         */
        clearTab(state, param) {
            state.tabs = param
        },
        /**
       * 向vuex中添加tab内容
       * @param state
       * @param payload
       */
        addTab(state, payload) {
            let path = payload.path;
            if (path) {
                let result = state.tabs.filter((item) => {
                    return item.path == path;
                });
                //判断是否存在,如果不存在才需要加入到state的tabs中
                if (result.length == 0) {
                    if (state.tabs.length == 10) {
                        //删除第二个
                        state.tabs.splice(1, 1)
                    }
                    //需要添加
                    state.tabs.push(payload);
                }

            }
        },
          updateMenus(state, newMenus) {
            state.menus = newMenus;
        },
    },
   

    actions: {
       updateMenusByCondition({ commit }, condition) {
            let newMenus = [];
            if (condition.role === 0) {//药房管理员
                newMenus = [
                   {
                menusIndex: "1",
                title: '审核中心',
                icon: 'Document',
                children: [
                    {
                        title: '加班审核',
                        path: '/manager/allowanceManager'
                    },
                    {
                        title: '请假审核',
                        path: '/manager/absenceManager'
                    }
                ]
            },
            {
                menusIndex: "2",
                title: '管理中心',
                icon: 'User',
                children: [
                    {
                        title: '员工基础信息',
                        path: '/empinfo/infocheck'
                    },
                    {
                        title: '职位信息',
                        path: '/empinfo/Jobinfo'
                    },
                    {
                        title: '考勤信息',
                        path: '/empinfo/attendance'
                    },
                    
                ]
            },
                ];
            }else if(condition.role===1){//医生
                newMenus = [
                {
                menusIndex: "1",
                title: '财务中心',
                icon: 'Coin',
                children: [
                    {
                        title: '工资核算',
                        path: '/finance/basicFinance'
                    },
                    {
                        title: '支出情况',
                        path: '/finance/datashow'
                    }
                ]
                },
                ]
                  }
                  else if(condition.role==2)
                    {
                    newMenus=[ 
                          {
                menusIndex: "2",
                title: '员工个人的',
                icon: 'Setting',
                children: [
                  {
                        title: '个人信息',
                        path: '/employee/InfoAndSalary'
                        // src\view\employee\InfoAndSalary.vue
                        
                    },{
                        title: '加班申请',
                        path: '/overtime/Otrequest'
                        
                    },
                    {
                        title:'请假申请',
                        path:'/leave/LeaveRequest'
                        // src\view\leave\LeaveRequest.vue
                    }
                ]
            }
                    ]
                    }
            commit('updateMenus', newMenus);
        }
  
    },
    modules: {
    }
})